package com.itheima.controller.order;

import com.itheima.entity.Checkitem;
import com.itheima.message.BussinessSuccessMsg;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.QueryPageBean;
import com.itheima.pojo.Result;
import com.itheima.service.CheckItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "检查项管理")
@RestController
@RequestMapping("/checkitem")
public class CheckitemController {

    @DubboReference
    private CheckItemService checkItemService;

    @ApiOperation("新增检查项")
    @PostMapping
    public Result add(@RequestBody @Validated Checkitem checkitem) {
        checkItemService.add(checkitem);
        return Result.success(BussinessSuccessMsg.ADD_CHECKITEM_SUCCESS);
    }

    @ApiOperation("删除检查项")
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id) {
        checkItemService.deleteById(id);
        return Result.success(BussinessSuccessMsg.DELETE_CHECKITEM_SUCCESS);
    }

    @PutMapping
    @ApiOperation("修改检查项")
    public Result update(@RequestBody  @Validated Checkitem checkitem) {
        checkItemService.update(checkitem);
        return Result.success(BussinessSuccessMsg.EDIT_CHECKITEM_SUCCESS);
    }

    @GetMapping("/{id}")
    @ApiOperation("通过ID查询检查项")
    public Result findById(@PathVariable Integer id) {
        Checkitem checkitem = checkItemService.findOne(id);
        return Result.success(checkitem);
    }

    @PostMapping("/page")
    @ApiOperation("检查项分页查询")
    public Result selectPage(@RequestBody QueryPageBean queryPageBean) {
        PageResult<Checkitem> data = checkItemService.selectPage(queryPageBean);
        return Result.success(data);
    }

    @GetMapping("/list")
    @ApiOperation("检查项查询全部")
    public Result findAll() {
        List<Checkitem> data = checkItemService.findAll();
        return Result.success(data);
    }

}
